﻿using System;
using System.ComponentModel.Design;
using System.Runtime.InteropServices;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace theeg.DependencyAnalysis.VsAddin
{

    [PackageRegistration(UseManagedResourcesOnly = true)]
    [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
    [ProvideMenuResource("Menus.ctmenu", 1)]
    [ProvideToolWindow(typeof(EggAndGherkinToolWindow))]
    [Guid(GuidList.guidtheeg_DependencyAnalysis_VsAddinPkgString)]
    public sealed class theeg_DependencyAnalysis_VsAddinPackage : Package
    {
        private void ShowToolWindow(object sender, EventArgs e)
        {
            ToolWindowPane window = FindToolWindow(typeof(EggAndGherkinToolWindow), 0, true);
            if ((null == window) || (null == window.Frame))
            {
                throw new NotSupportedException(Resources.CanNotCreateWindow);
            }
            var windowFrame = (IVsWindowFrame)window.Frame;
            ErrorHandler.ThrowOnFailure(windowFrame.Show());
        }

        protected override void Initialize()
        {
            base.Initialize();
            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if (null != mcs)
            {
                var application = GetGlobalService(typeof(DTE)) as DTE2;
                EggAndGherkinToolWindow.ApplicationDte = application;

                var toolwndCommandId = new CommandID(GuidList.guidtheeg_DependencyAnalysis_VsAddinCmdSet, (int)PackageCommands.eggAndGherkinToolWindow);
                var menuToolWin = new MenuCommand(ShowToolWindow, toolwndCommandId);
                mcs.AddCommand(menuToolWin);
            }
        }
    }
}
